﻿using System.Linq;
using Microsoft.Samples.ServiceHosting.StorageClient;

namespace TweetPollDataService
{
    public class TweetPollDataServiceContext : TableStorageDataServiceContext
    {
        public TweetPollDataServiceContext(StorageAccountInfo accountInfo)
            : base(accountInfo)
        {
        }

        public const string TableName = "tweetpoll";
        public const string LongTweetsTableName = "longtweets";

        public IQueryable<LongTweetEntity> LongTweetsTable
        {
            get 
            { 
                return CreateQuery<LongTweetEntity>(LongTweetsTableName);
            }
        }

        public IQueryable<TweetPollEntity> Table
        {
            get
            {
                return CreateQuery<TweetPollEntity>(TableName);
            }
        }
        
        public IQueryable<TweetPollPageLoadCount> PageLoadCountTable
        {
            get
            {
                return CreateQuery<TweetPollPageLoadCount>(TableName);
            }
        }
    }

    public class LongTweetEntity : TableStorageEntity
    {
        public LongTweetEntity(string tweetText):base("LongTweet", tweetText)
        {
        }
        public LongTweetEntity()
        {
        }
    }

    public class TweetPollEntity : TableStorageEntity
    {
        public TweetPollEntity(string partitionKey, string rowKey, int count)
            : base(partitionKey, rowKey)
        {
            Count = count;
        }

        public TweetPollEntity()
            : base()
        {
            Count = 0;
        }

        public int Count
        {
            get;
            set;
        }
    }

    public class TweetPollPageLoadCount : TableStorageEntity
    {
        public TweetPollPageLoadCount(string partitionKey, string rowKey, int count)
            : base(partitionKey, rowKey)
        {
            Count = count;
        }

        public TweetPollPageLoadCount()
            : base()
        {
            Count = 0;
        }

        public int Count
        {
            get;
            set;
        }
    }
}
